package extrace.loader;

import java.util.List;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;

import com.google.gson.reflect.TypeToken;

import extrace.misc.model.ExpressSheet;
import extrace.misc.model.UserInfo;
import extrace.net.HttpAsyncTask;
import extrace.net.HttpResponseParam.RETURN_STATUS;
import extrace.net.IDataAdapter;
import extrace.net.JsonUtils;
import extrace.ui.main.ExTraceApplication;
import extrace.ui.main.MyFragment;

public class LoginLoader extends HttpAsyncTask {


    private static final String TAG = "login";
    String url;

    private Activity context;

    public LoginLoader(Activity context) {
        super(context);
        this.context = context;


        url = ((ExTraceApplication) context.getApplication()).getDomainServiceUrl();
    }

    @Override
    public void onDataReceive(String class_data, String json_data) {
        Log.v(TAG, "onDataReceive: " + class_data + json_data);
        if (json_data != null) {
            UserInfo userInfo = JsonUtils.fromJson(json_data, UserInfo.class);
            ((ExTraceApplication) context.getApplication()).setLoginUser(userInfo);
            context.finish();
        }else {

        }

    }



    @Override
    public void onStatusNotify(RETURN_STATUS status, String str_response) {
        Log.i("onStatusNotify", "onStatusNotify: " + str_response);
    }

    public void doLogin(int uid, String pwd) {
        url += "doLogin_c/" + uid + "/" + pwd + "?_type=json";
        Log.i("32", url);
        try {
            execute(url, "GET");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
